package com.lpy.book.model;


import lombok.Data;

@Data
public class Result<T> {
    private Integer code; // 业务状态码 200---成功 -1---失败 -2---未登录
    private String errmsg; // 后端发送错误的原因
    private Object data;

//    成功的时候
    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<T>();
        result.setData(data);
        result.setCode(200);

        return result;
    }
//    失败的时候
    public static <T> Result<T> fail(T data, String errmsg) {

        Result<T> result = new Result<T>();
        result.setData(data);
        result.setCode(-1);
        result.setErrmsg(errmsg);

        return result;
    }
    public static <T> Result<T> fail(String errmsg) {

        Result<T> result = new Result<T>();
        result.setCode(-1);
        result.setErrmsg(errmsg);

        return result;
    }

//    未登录的时候
    public static <T> Result<T> unlogin() {

        Result<T> result = new Result<T>();
        result.setCode(-2);
        result.setErrmsg("用户未登录");

        return result;
    }
}
